#include "map.h"

//ALLEGRO_BITMAP *Map::bmap = NULL; //Bitmaps::get_default_bitmap(SAND);

Movable_type Map::element(int x_loc, int y_loc)
{
	return _screen_map[x_loc][y_loc];
}
	
void Map::set_type(Movable_type type, int x_loc, int y_loc)
{
	 Map::_screen_map[x_loc][y_loc] = type;
}

 ALLEGRO_BITMAP *Map::bitmap()
 {
	 return Bitmaps::get_default_bitmap(SAND);
 }

 void Map::generate_default_map()
{


	draw_sand();
	draw_holes(3,7,16,9);
	draw_holes(19, 1, 21, 21);
	draw_holes (1,22,11,24);
	draw_holes (35, 10, 37,25);


	
}

 void Map::setBitmap()
 {
	 Bitmaps::get_default_bitmap(SAND);
 }

 void Map::plot_movable_on_map(Movables& const movable)
 {
	int x_pos = movable.x();
	int y_pos = movable.y();
	int radius = movable.radius();

	for(int i = -radius; i <= radius; i++)
	{
		for(int j = -radius; j <= radius; j++)
		{
			_screen_map.at(x_pos + i).at(y_pos + j) = movable.type();		
		}
	}
}

 void Map::remove_movable_from_map(Movables& const movable)
 {
	int x_pos = movable.x();
	int y_pos = movable.y();
	int radius = movable.radius();

	for(int i = -radius; i <= radius; i++)
	{
		for(int j = -radius; j <= radius; j++)
		{
			_screen_map[x_pos + i][y_pos + j] = HOLE;		
		}
	}
}



 void Map::draw_holes(int x_s, int y_s, int x_e, int y_e)
 {
	 for(int i = x_s; i <= x_e; i++)
	 {
		 for(int j = y_s; j <= y_e; j++)
		 {
			 _screen_map[i][j] = HOLE;
		 }
	 }
 }

 void Map::draw_sand()
 {

	vector<Movable_type> _line_map;

	vector<vector<Movable_type>> _lines_map;

 	for(int i =0; i < game_grid_elements; i++)
	{
		_line_map.clear();

		for(int j = 0; j < game_grid_elements; j++)
		{
			_line_map.push_back(SAND);
		}
		_lines_map.push_back(_line_map);
	}

	
	_screen_map = _lines_map;
 }